import {
  AbilityType,
  APIType,
  APIVersion,
  compileVersion,
  LanguageType,
  ModuleTemplateType,
  RuntimeOSType,
  SDKType
} from '../../../../../models/constants';
import { ProjectTemplateOption, ProjectTemplateOptionBuilder } from '../../../../../models/model-options';
import { ProjectConfigInitFun } from '../../../../../models/project-models';
import { copyTmp, DirTemplateCreator, dirTmp, renderTmp } from '../../../../../models/template-models';
import { projectBuilder } from '../../../../../project-builder';


/**
 * 工程选项
 *
 * @type {ProjectTemplateOption}
 */
const option: ProjectTemplateOption = ProjectTemplateOptionBuilder.builder()
  .sdk(SDKType.Single)
  .apiType(APIType.FA)
  .abilityType(AbilityType.Application)
  .apiVersion(APIVersion.API10)
  .language(LanguageType.ArkTs)
  .runtimeOS(RuntimeOSType.HarmonyOS)
  .build();


const api10FAStageProject: DirTemplateCreator = (dirName) => dirTmp(dirName)
  .add(renderTmp('/project/common/build-profile.json5'))
  .add(copyTmp('/project/api10/fa/app/hvigorfile.ts'))
  .add(renderTmp('/project/common/local.properties'))
  .add(copyTmp('/project/common/hvigor'))
  .add(renderTmp('/project/api10/fa/app/oh-package.json5'));


const initFun: ProjectConfigInitFun = async (name, option, modules, template) => {
  template.node('build-profile.json5').data = {
    apiVersion: compileVersion(option.apiVersion, option.runtimeOS),
    runtimeOS: option.runtimeOS,
    modules: Object.values(modules).map(module => {
      return {
        moduleName: module.name,
        hasTarget: module.option.moduleTemplateType !== ModuleTemplateType.StaticLibrary
          && module.option.moduleTemplateType !== ModuleTemplateType.VisualLibrary
      };
    })
  };

  template.node('oh-package.json5').data = {
    projectName: name
  };
};


projectBuilder.add(option, api10FAStageProject, initFun);
